//package org.csu.mypetstore.controller.admin;
//
//import org.csu.mypetstore.domain.PO.Admin;
//import org.csu.mypetstore.domain.PO.Order;
//import org.csu.mypetstore.service.OrderService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.SessionAttributes;
//
//import java.text.SimpleDateFormat;
//import java.util.List;
//
//@Controller
//@SessionAttributes(value = {"admin"})
//public class AdminOrderController {
//
//    private static SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy");
//    @Autowired
//    private OrderService orderService;
//
//
//    @ResponseBody
//    @GetMapping("/getAllOrder")
//    public List<Order> getAllOrder(Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            List<Order> orderList = orderService.getAllAccountOrder();
//            return orderList;
//        }
//        return null;
//    }
//
//    //查找某一特定用户的订单,返回该用户的json字符串
//    @ResponseBody
//    @GetMapping("/adminFindOrder")
//    public String adminFindOrderByUsername(String username , Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            List<Order> orderList = orderService.getOrdersByUsername(username);
//            model.addAttribute("adminOrderList",orderList);
//            return orderList.toString();
//        }
//        return null;
//    }
//
//    //删除该订单，并向该订单的用户发送一条消息，保存在数据库中存储,message为发送给信息
//    @ResponseBody
//    @PostMapping("/adminDeleteOrder")
//    public void adminDeleteOrder(int orderId,String username,Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            orderService.adminDeleteOrder(orderId,username,"亲爱的" + username + "你好，" + "因为某种缘故，很抱歉取消您的订单，您的钱已返还给您，请及时查看");
//        }
//    }
//
//    //发货，并向该订单的用户发送一条消息，保存在数据库中存储
//    @ResponseBody
//    @PostMapping("/adminSendOrder")
//    public void adminSendOrder(int orderId,String username,String message,Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            orderService.adminSendOrder(orderId,username,"亲爱的" + username + "你好，" + "您的订单已经发货，感谢购买该商品");
//        }                        //重置了orderList
//        //表示发货成功
//    }
//
//    @ResponseBody
//    @PostMapping("/adminInsertOrder")
//    public void  adminInsertOrder(int orderId, Model model){
//        Admin loginAdmin = (Admin) model.getAttribute("admin");
//        if (loginAdmin != null && loginAdmin.getAdminname() != null){
//            Order order = new Order();
//            order.setOrderId(orderId);
//            order.setStatus("");
//            order.setUsername("");
//            order.setCourier("");
//            order.setLocale("");
//            order.setOrderDate(null);
//            order.setTotalPrice(null);
//            order.setBillAddress1("");
//            order.setBillAddress2("");
//            order.setBillCity("");
//            order.setBillCountry("");
//            order.setBillState("");
//            order.setBillToFirstName("");
//            order.setBillToLastName("");
//            order.setBillZip("");
//            order.setExpiryDate("");
//            order.setShipAddress1("");
//            order.setShipAddress2("");
//            order.setShipCity("");
//            order.setShipCountry("");
//            order.setShipToFirstName("");
//            order.setShipToLastName("");
//            order.setShipZip("");
//            order.setStatus("");
//            order.setBillState("");
//            orderService.insertOrder(order);
//        }
//    }
//
//
////    public void adminDeleteOrder(int orderid,String userid,Model model){
////        List<Order> orderList = (List<Order>) model.getAttribute("orderList");
////        orderService.adminDeleteOrder(orderid,userid,orderList);                        //重置了orderList
////        model.addAttribute("adminOrderList",orderList);
////    }
//
////    //从管理员界面去查看order订单信息,返回所有订单的json字符串
////    @ResponseBody
////    @GetMapping("/adminViewOrderList")
////    public String adminViewOrderList(Model model){
////        List<Order> orderList = orderService.getAllAccountOrder();
////        model.addAttribute("adminOrderList",orderList);
////        return orderList.toString();
////    }
//}
